package cn.com.server.service.impl;

import cn.com.server.common.AjaxObject;
import cn.com.server.dao.SqlSessionDao;
import cn.com.server.service.SqlSession;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 通用sql服务实现类
 * </p>
 *
 * @author qing
 * @since 2017-11-15
 */
@Service
public class SqlSessionImp implements SqlSession {
	
	@Autowired
	private SqlSessionDao sqlSessionDao;

	@Override
	public long selectCount(String sql) {
		return sqlSessionDao.selectCount(sql);
	}

	@Override
	public String selectString(String sql) {
		return sqlSessionDao.selectString(sql);
	}

	@Override
	public List<Map<String, Object>> selectList(String sql) {
		return sqlSessionDao.selectList(sql);
	}

	@Override
	public AjaxObject selectPage(String sql,Integer page,Integer limit) {
		page = (page==null||page<1)?1:page;
		limit = (limit==null||limit<1)?10:limit;
		PageHelper.startPage(page, limit);
		Page<Map<String, Object>> pageData = sqlSessionDao.selectListPage(sql);
		AjaxObject ajaxObject = new AjaxObject(0,"获取分页数据成功",pageData);
		return ajaxObject;
	}

	@Override
	public int insertSql(String sql) {
		return sqlSessionDao.insertSql(sql);
	}

	@Override
	public int updateSql(String sql) {
		return sqlSessionDao.updateSql(sql);
	}
	
}
